/**
 * Created by zjw on 16/8/31.
 */
define([], function() {
    'use strict';
    console.log("this is AppRouter.js:");
    return angular.module('app')
        .config(['$urlRouterProvider', '$stateProvider', '$ocLazyLoadProvider', function($urlRouterProvider, $stateProvider, $ocLazyLoadProvider) {

            var routerArr = [{
                    name: 'login',
                    url: '/login',
                    controller: 'LoginController',
                    templateUrl: '/src/login/login.html',
                    resolve: {
                        'deps': ['$ocLazyLoad', '$q', function($ocLazyLoad, $q) {
                            var defer = $q.defer();

                            require(['login/loginController'], function() {
                                $ocLazyLoad.inject('login').then(function() {
                                    defer.resolve();
                                });
                            })
                            return defer.promise;
                        }]
                    }
                },
                {
                    name: 'store',
                    url: '/store',
                    views: {
                        'header': {
                            templateUrl: '/src/header/header.html',
                            controller: 'HeaderController'
                        },
                        'footer': {
                            templateUrl: '/src/footer/footer.html',
                            controller: 'FooterController'
                        }
                    },
                    resolve: {
                        'deps': ['$ocLazyLoad', '$q', function($ocLazyLoad, $q) {
                            var defer = $q.defer();

                            require(['header/headerController', 'footer/footerController'], function() {
                                defer.resolve();
                                // $ocLazyLoad.inject('login').then(function() {
                                //     defer.resolve();
                                // });
                            })
                            return defer.promise;
                        }]
                    }
                },
                {
                    name: 'store.home',
                    url: '/home',
                    controller: 'HomeController',
                    templateUrl: '/src/home/home.html',
                    resolve: {
                        'deps': ['$ocLazyLoad', '$q', function($ocLazyLoad, $q) {
                            var defer = $q.defer();

                            require(['home/homeController'], function() {
                                $ocLazyLoad.inject('home').then(function() {
                                    defer.resolve();
                                });
                            })
                            return defer.promise;
                        }]
                    }
                }
            ];

            angular.forEach(routerArr, function(router) {
                $stateProvider.state(router);
            });

            $urlRouterProvider.otherwise('/login');
        }]);
});